package com.yanqu.road.entity.activity.daomu.skillstrategy.passive.impl;

import com.yanqu.road.entity.activity.daomu.DaoMuAttribute;
import com.yanqu.road.entity.activity.daomu.DaoMuSkill;
import com.yanqu.road.entity.activity.daomu.config.DaoMuSkillConfig;
import com.yanqu.road.entity.activity.daomu.enums.DaoMuAttributeEnum;
import com.yanqu.road.entity.activity.daomu.skillstrategy.passive.ISkillPassiveStrategy;
import com.yanqu.road.entity.activity.daomu.skillstrategy.passive.req.DaoMuPassiveSkillCountAttributeReq;
import com.yanqu.road.utils.string.StringUtils;

/**
 * 长明灯
 */
public class SkillLampStrategy implements ISkillPassiveStrategy {

    /**
     * 计算属性MAP
     * @param req
     */
    @Override
    public void countAttribute(DaoMuPassiveSkillCountAttributeReq req) {
        //技能配置
        DaoMuSkillConfig daoMuSkillConfig = req.getDaoMuSkillConfig();
        String[] skillParaArr = daoMuSkillConfig.getSkillPara().split("\\|");
        //加攻击力千分比（每拥有{num}个主动型藏品技能数量;增加{addAttRate}攻击力千分比)
        String addAttParamStr = skillParaArr[40];
        String[] addAttParamStrArr = addAttParamStr.split(";");
        int num = Integer.parseInt(addAttParamStrArr[0]);
        long addRate = Long.parseLong(addAttParamStrArr[1]);
        //特殊加成
        int skillNum = req.getActiveSkillMap().size();
        int addTime = skillNum / num;
        addRate = addRate * addTime;
        //特殊效果-加攻击力千分比（每拥有满级主动型藏品技能数量;增加攻击力千分比)
        String specialParamStr = skillParaArr[41];
        if (!StringUtils.isNullOrEmpty(specialParamStr) && !specialParamStr.equals("0")) {
            int fullNum = 0;
            for (DaoMuSkill daoMuSkill : req.getActiveSkillMap().values()) {
                if (daoMuSkill.isFullLevelFlag()) {
                    fullNum++;
                }
            }
            String[] paramArr = specialParamStr.split(";");
            int specialNum = Integer.parseInt(paramArr[0]);
            long specialAddAttRate = Long.parseLong(paramArr[1]);
            int specialAddTime = fullNum / specialNum;
            addRate += specialAddTime * specialAddAttRate;
        }
        //攻击属性
        DaoMuAttribute attAttribute = req.getAttributeMap().get(DaoMuAttributeEnum.ATTRIBUTE_ATT.getType());
        attAttribute.addAddRate(addRate);
    }
}
